package com.fyl.pattern.interpreter;

public class Client {
    public static void main(String[] args) {

        //创建环境对象
        Context context = new Context();

        //创建变量
        Variable a = new Variable("a");
        Variable b = new Variable("b");
        Variable c = new Variable("c");
        Variable d = new Variable("d");

        //存储变量
        context.assign(a,1);
        context.assign(b,2);
        context.assign(c,3);
        context.assign(d,4);

        //定义计算语法规则
        AbstractExpression expression = new Plus(a,new Plus(new Plus(b,c),d));

        //计算
        int result = expression.interpret(context);

        System.out.println(expression+" = " + result);
    }
}
